cmake_minimum_required(VERSION 3.5)
project(cloud_filter)
cmake_policy(SET CMP0074 NEW)

# 找到所需的包
find_package(yaml-cpp REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(livox_ros_driver2 REQUIRED)
find_package(PCL REQUIRED)
find_package(tf2_ros REQUIRED)

# 包含目录
include_directories(
        include
        ${visualization_msgs_INCLUDE_DIRS}
        ${livox_ros_driver2_INCLUDE_DIRS}
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${PCL_INCLUDE_DIRS}
)

# 设置YAML文件路径
set(YAML_FILE_PATH "${CMAKE_SOURCE_DIR}/config/config.yaml")

# 添加库文件
add_library(cloud_filter_lib src/lib/cloud_filter.cpp src/lib/cube.cpp)

# 添加可执行文件
add_executable(filter_node src/pointcloud/filter.cpp src/pointcloud/filter_custom.cpp)
add_executable(MarkerViz src/lib/MarkerViz.cpp)

# 设置可执行文件的包含目录
target_include_directories(filter_node PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)
target_include_directories(MarkerViz PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)
# 指定C++标准
target_compile_features(filter_node PUBLIC c_std_99 cxx_std_17)
target_compile_features(MarkerViz PUBLIC c_std_99 cxx_std_17)
# 设置ament依赖
ament_target_dependencies(filter_node
        "rclcpp"
        "livox_ros_driver2"
)
ament_target_dependencies(MarkerViz
        "rclcpp"
)

# 链接库
target_link_libraries(cloud_filter_lib
        ${tf2_ros_LIBRARIES}
        yaml-cpp
)

target_link_libraries(filter_node
        cloud_filter_lib
        rclcpp::rclcpp
        ${tf2_ros_LIBRARIES}
        ${PCL_LIBRARIES}
)
target_link_libraries(MarkerViz
        yaml-cpp
        rclcpp::rclcpp
        ${tf2_ros_LIBRARIES}
        ${PCL_LIBRARIES}
        ${visualization_msgs_LIBRARIES}
)

# 安装目标文件
install(TARGETS
        cloud_filter_lib
        MarkerViz
        filter_node
        DESTINATION lib/${PROJECT_NAME}
)

# 安装launch文件
install(DIRECTORY launch/ DESTINATION share/${PROJECT_NAME}/launch)

# 设置编译时定义
target_compile_definitions(MarkerViz PRIVATE YAML_FILE_PATH="${YAML_FILE_PATH}")
target_compile_definitions(cloud_filter_lib PRIVATE YAML_FILE_PATH="${YAML_FILE_PATH}")
target_compile_definitions(filter_node PRIVATE YAML_FILE_PATH="${YAML_FILE_PATH}")

# 设置ament依赖项
ament_target_dependencies(cloud_filter_lib
        tf2_geometry_msgs
)

ament_target_dependencies(MarkerViz
        tf2_geometry_msgs
        pcl_conversions
)

ament_target_dependencies(filter_node
        visualization_msgs
        tf2_geometry_msgs
)

# 结束
ament_package()
